<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@include file="../base.jsp" %> 
<sys:genericTag4o id="menusByUser" methodName="queryMenusByUser" className="com.tmpt.controller.taglib.SecurityV2Tag"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>    
</head>
<body class="font14">

<script type="text/javascript">
var menusByUserStr = '${menusByUser}';
var menusByUser = $.parseJSON(menusByUserStr);
$(function(){
	$('#_start_menu_tree11').treegrid({ 
		data:menusByUser,
		checkbox: false,
		rownumbers: false,
		showHeader:false,
		idField: 'id',
		treeField:'text', 
		columns:[[ 
		{title:'菜单名称',field:'text',width:200}, 
		{field:'opt',title:'操作',width:150,align:'left',
			formatter:function(value,rowData){ 
				//var rowDataStr = JSON.stringify(rowData);
				var _id = rowData.id;
				//一级菜单格式："id":"1"
				//二级菜单格式："id":"1_16"
				if(_id.indexOf('_')!=-1){
					var btn = '';
					btn += "<a class=\"_send2Desktop\" onclick=\"_send2Desktop('"+_id+"')\" href=\"javascript:void(0)\">发送到桌面</a> ";  
					return btn;
				}
				return "";
			}
		}
		]] 
	});
	
	$('._send2Desktop').linkbutton({plain:true,iconCls:'icon-add'});  //给每行后的button加easyui样式
	
});

function _send2Desktop(_id){
	$.each(menusByUser, function(indexF,father){
		$.each(father.children,function(indexS,son){
			if(son.id == _id){
				var sonId = son.id;
				var sonText = son.text;
				var sonHref = son.href;
				_sendAjax(sonId,sonText,sonHref);
				//
				return;
			}
		});
	});
}

function _sendAjax(sonId,sonText,sonHref){
	var data = {
		'menuId':sonId,
		'text':sonText,
		'href':sonHref
	}
	$.ajax({
		type:"POST",
		url:'desktopAjax_addMenu2Desktop.action',
		dataType:"json",
		data:data,
		success:function(msg){
			window.parent.refreshapp();
		},
		error:function(er){
			alert(er.responseText.trim());
		}
	});
}

</script>

		<div id="_start_menu_tree11" 
			style="width: 325px;height: 600px;" ></div>


</body>
</html>